def main(host):
    from .wsgi import app, init_db
    with app.app_context():
        init_db()
    host = host.split(':', maxsplit=1)
    if len(host) >= 2:
        port = int(host[1])
        host = host[0]
        if not host:
            host = '0.0.0.0'
    else:
        port = 80
        host = host[0]
        try:
            port = int(host)
        except ValueError:
            pass
        else:
            host = '0.0.0.0'
    print('Listening at {}:{}'.format(host, port))
    app.run(host=host, port=port)
    return 0

if __name__ == '__main__':
    import sys
    main(sys.argv[1])
